package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.app.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

//操作图片资源的控制器
@RestController
@RequestMapping("/images")
public class ImageController {
    //测试提交
    @PostMapping
    public Object upload(@RequestParam MultipartFile pic) {
        //把上传的图片保存到本地图库
        String url = UploadUtil.uploadQiniu(pic);
        //并且把图片的地址返回
        //{"url":url, "uploaded":1}
        Map<String, Object> map = new HashMap<>();
        map.put("url", url);
        map.put("uploaded", 1);
        return map;
    }
}
